package com.fare.taluo.application.impl.report;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fare.taluo.application.report.csair.CsairReportApplication;
import com.fare.taluo.core.domain.analyse.report.CsairReportEntity;
import com.fare.taluo.util.DateUtils;
import com.fare.taluo.vo.report.CsairReportVO;

@Transactional
@Scope("singleton")
@Service("csairReportApplication")
public class CsairReportApplicatioinImpl implements CsairReportApplication{

	@Override
	public List<CsairReportVO> findCsairReportVO_15() {
		String nowaday15=com.fare.taluo.util.DateUtils.formatFutureDay(new Date(), "yyyy-MM-dd", 15);
		List<CsairReportEntity> entitylist=CsairReportEntity.findCsairEntityAll(nowaday15);
		return showCsairVO(entitylist);
	}
	@Override
	public List<CsairReportVO> findCsairReportVO_30() {
		String nowaday30=com.fare.taluo.util.DateUtils.formatFutureDay(new Date(), "yyyy-MM-dd", 30);
		List<CsairReportEntity> entitylist=CsairReportEntity.findCsairEntityAll(nowaday30);
		return showCsairVO(entitylist);
	}
	
	public List<CsairReportVO> showCsairVO(List<CsairReportEntity> entitylist){
		List<CsairReportVO> volist=new ArrayList<CsairReportVO>();
		if(entitylist !=null && entitylist.size()>0){
			for(CsairReportEntity entity:entitylist){
				CsairReportVO vo=new CsairReportVO();
				vo.setId(entity.getId());
				vo.setGrabTime(entity.getGrabTime());
				vo.setDeprotDate(entity.getDeprotDate());
				vo.setFlightDate(entity.getFlightDate());
				vo.setFlightNo(entity.getFlightNo());
				vo.setFlightType(entity.getFlightType());
				vo.setFromCity(entity.getFromCity());
				vo.setFromCityName(entity.getFromCityName());
				vo.setPrice(entity.getPrice());
				vo.setQunaerAgentAdderss(entity.getQunaerAgentAdderss());
				vo.setQunaerAgentName(entity.getQunaerAgentName());
				vo.setQunaerPrice(entity.getQunaerPrice());
				vo.setQunaerSpread(entity.getQunaerSpread()!= null ? entity.getQunaerSpread()*100 : null);
				vo.setQunaerSpreadAmount(entity.getQunaerSpreadAmount());
				vo.setTabaoAgentAddess(entity.getTabaoAgentAddess());
				vo.setTaobaoAgentName(entity.getTaobaoAgentName());
				vo.setTaobaoPric(entity.getTaobaoPric());
				vo.setTaobaoSpread(entity.getTaobaoSpread()!= null ? entity.getTaobaoSpread()*100 : null);
				vo.setTaobaoSpreadAmount(entity.getTaobaoSpreadAmount());
				vo.setToCity(entity.getToCity());
				vo.setToCityName(entity.getToCityName());
				vo.setType(entity.getType());
				vo.setHbaseKey(entity.getHbaseKey());
				vo.setChannel(entity.getChannel());
				vo.setFlightTime(DateUtils.formatDay(entity.getFlightDate(), "MM-dd"));
				vo.setFlightDateStr(DateUtils.formatDay(entity.getFlightDate(), "yyyy-MM-dd"));
				vo.setGrabDateStr(DateUtils.formatDay(entity.getGrabTime(), "yyyy-MM-dd hh:mm"));
				volist.add(vo);
			}
		}
		return volist;
	}
	@Override
	public List<CsairReportVO> findCsairEntityVOByDate(String dateStr) {
		// TODO Auto-generated method stub
		return null;
	}
	public List<CsairReportVO> findCsairEntityByCondition(String hbaseKey,String fromCityCode,String toCityCode,String startDate,String endDate,String flightDate, String grabDate, String grabHbaseKey,String type)
	{
		CsairReportEntity csairReportEntity=new CsairReportEntity();
		List<CsairReportEntity> entitylist=csairReportEntity.findCsairEntityByCondition(hbaseKey, fromCityCode, toCityCode, startDate, endDate, flightDate, grabDate,  grabHbaseKey, type);
		return showCsairVO(entitylist);
	}
	@Override
	public List<CsairReportVO> findCsairReportVO_7() {
		String nowaday7=com.fare.taluo.util.DateUtils.formatFutureDay(new Date(), "yyyy-MM-dd", 7);
		List<CsairReportEntity> entitylist=CsairReportEntity.findCsairEntityAll(nowaday7);
		return showCsairVO(entitylist);
	}
}
